(function () {
    var serverData = {};
    var serverTable;
    var serverData2 = {};
    var serverTable2;
    //查询 
    jQuery('.searchBtn').on('click',function(){
        serverData.key=jQuery('#keyword').val();
        serverTable.draw();
    })
    //撤销查询
    jQuery('.cancelBtn').on("click",function()
    {
        jQuery('#keyword').val('');
        serverData.key ='';
        serverTable.draw();
    });
    
    jQuery(document).ready(function () {
        serverTable = jQuery('#myTable').DataTable({
        	"serverSide": true,
        	"ordering": false,
        	"ajax": {
        		"dataType": "json",
        		"type": "get",
        		"cache": false,
        		"url":window.rootPath+ '/ui/productPlan/getpage',
        		"data": function (d) {
        			return $.extend({}, d, serverData);
        		}
        	},
            "columns" : [{
                            data : null,
                            defaultContent : ""// 排序   1
                        },                       
        	            {
                            data: 'cProductPlanNumber'
                        },
        	            {
        	                data: 'cProcess'
        	            },
        	            {
        	                data: 'dIssueDate',
        	            	render: function (data, type, full, meta) {
        	                    if (data)
        	                        return moment(data).format('YYYY/MM/DD');
        	                    else
        	                        return '';
        	                }
        	            },
        	            {
        	                data: 'cState'
        	                
        	            },
        	            {
       		        	 	data: 'cContractNumber'
        	            },
        	            {
        	                data: 'cProductKind'
        	                
        	            },
        	            {
        	                data: 'cProductType',
        					render:function(data,type,full,meta){
        						if(data == null || data == undefined || data == ""){
        							return data;
        						}else{
        							return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
        						}
        					}
        	                
        	            },
        	            {
        	                data: 'nCount'
        	                
        	            },
        	            {
        	            	data: 'dOutDate',
        	            	render: function (data, type, full, meta) {
        	                    if (data)
        	                        return moment(data).format('YYYY/MM/DD');
        	                    else
        	                        return '';
        	                }
        	            		
        	            },
        	            {
        	            	data: 'dOrderDate',
        	            	render: function (data, type, full, meta) {
        	                    if (data)
        	                        return moment(data).format('YYYY/MM/DD');
        	                    else
        	                        return '';
        	                }
        	            		
        	            },
        	            {
        	            	data: 'cStoreageNumber'
        	            		
        	            },
        	            {
        	            	data: 'dStoreageDate',
        	            	render: function (data, type, full, meta) {
        	                    if (data)
        	                        return moment(data).format('YYYY/MM/DD');
        	                    else
        	                        return '';
        	                }
        	            		
        	            },
        	            {
        	            	data: 'cMachine',
        					render:function(data,type,full,meta){
        						if(data == null || data == undefined || data == ""){
        							return data;
        						}else{
        							return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
        						}
        					}
        	            		
        	            },
        	            {
        	            	data: 'cPressure'
        	            		
        	            },
        	            {
        	            	data: 'cFlow'
        	            		
        	            },
        	            {
        	            	data: 'cPower'
        	            		
        	            },
        	            {
        	            	data: 'cOtherRequest',
        					render:function(data,type,full,meta){
        						if(data == null || data == undefined || data == ""){
        							return data;
        						}else{
        							return (data.length > 5) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
        						}
        					}
        	            		
        	            },
        	            {
        	            	data: 'cMemo',
        					render:function(data,type,full,meta){
        						if(data == null || data == undefined || data == ""){
        							return data;
        						}else{
        							return (data.length > 6) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
        						}
        					}
        	            		
        	            },
        	            {
        	            	data: 'cContractSplitState'
        	            		
        	            },
        	            {
        	            	data: 'cContractSplitPersonName'
        	            		
        	            },
        	            {
        	            	data: 'dContractBeginDate',
        	            	render: function (data, type, full, meta) {
        	                    if (data)
        	                        return moment(data).format('YYYY/MM/DD');
        	                    else
        	                        return '';
        	                }
        	            		
        	            },
        	            {
        	            	data: 'dContractEndDate',
        	            	render: function (data, type, full, meta) {
        	                    if (data)
        	                        return moment(data).format('YYYY/MM/DD');
        	                    else
        	                        return '';
        	                }
        	            		
        	            },
        	            {
        	            	data: 'cTechnologyPlanState'
        	            		
        	            },
        	            {
        	            	data: 'cTechnologyPlanPersonName'
        	            		
        	            },
        	            {
        	            	data: 'dTechnologyPlanBeginDate',
        	            	render: function (data, type, full, meta) {
        	                    if (data)
        	                        return moment(data).format('YYYY/MM/DD');
        	                    else
        	                        return '';
        	                }
        	            		
        	            },
        	            {
        	            	data: 'dTechnologyPlanEndDate',
        	            	render: function (data, type, full, meta) {
        	                    if (data)
        	                        return moment(data).format('YYYY/MM/DD');
        	                    else
        	                        return '';
        	                }
        	            		
        	            },
        	            {
        	            	data: 'cOperationPlanPersonName'
        	            		
        	            },
        	            {
        	            	data: 'cCreateUser'
        	            		
        	            },
        	            {
        	            	data: 'dCreateDate',
        	            	render: function (data, type, full, meta) {
        	                    if (data)
        	                        return moment(data).format('YYYY/MM/DD');
        	                    else
        	                        return '';
        	                }
        	            		
        	            }
        	            ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
                //单击商品计划表加载商品计划明细
                serverTable.off('click', 'tr');
                serverTable.on('click','tr',function(event) {
                	event = event|| window.event;
                	var target = event.target|| event.scrElement;
                	var data = serverTable.row(this).data();
                	var a = data.id;
                	serverData2.id = data.id;
                	serverTable2.draw();
                	return;
                });
            }
        });
        
        
        
        
        serverTable2 = jQuery('#myTranceTable').DataTable({
        	"serverSide": true,
        	"ordering": false,
        	"ajax": {
        		"dataType": "json",
        		"type": "get",
        		"cache": false,
        		"url":window.rootPath+ '/ui/productPlan/getProduct',
        		"data": function (d) {
        			return $.extend({}, d, serverData2);
        		}
        	},
            "columns" : [{
                            data : 'cPartPicNumDes',
                        },                       
        	            {
                            data: 'cPartName'
                        },
        	            {
        	                data: 'cMaterial'
        	            },
        	            {
        	                data: 'nTotalCount'
        	            },
        	            {
        	                data: 'cConfigurationType'
        	                
        	            }
        	            ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
    });
})();